import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';
import 'package:flutter_changdian_football/pages/home/home_controller.dart';
import 'package:flutter_changdian_football/pages/home/widget/icon_text_widget.dart';
import 'package:flutter_changdian_football/routers/app_routes.dart';
import 'package:flutter_changdian_football/utils/custom_constant.dart';
import 'package:flutter_changdian_football/utils/show_sheet_utils.dart';
import 'package:flutter_changdian_football/utils/str_utils.dart';
import 'package:flutter_changdian_football/widget/screenutil/custom_screenutil.dart';
import 'package:flutter_changdian_football/widget/sheet/share_icon_sheet.dart';
import 'package:get/get.dart';

/// Banner和功能区
class BannerAndRibbonWidget extends StatelessWidget {
  const BannerAndRibbonWidget({super.key});

  @override
  Widget build(BuildContext context) {
    return SliverToBoxAdapter(
      child: GetBuilder<HomeController>(
        builder: (homeController) {
          return SizedBox(
            // padding: EdgeInsets.symmetric(horizontal: 17.w),
            child: Column(
              children: [
                Stack(
                  alignment: Alignment.bottomCenter,
                  children: [
                    CarouselSlider.builder(
                      itemCount: homeController.indexPageBaseInfoModel?.carousels?.length, 
                      carouselController: homeController.carouselController,
                      itemBuilder: (context, index, realIndex) {
                        return SizedBox(
                          width: double.infinity,
                          child: Image.network(homeController.indexPageBaseInfoModel?.carousels?[index].showImg ?? '', fit: BoxFit.fill, gaplessPlayback: true, excludeFromSemantics: true,),
                        );
                      }, 
                      options: CarouselOptions(
                        // enlargeCenterPage: true, 
                        enlargeCenterPage: false,
                        height: 140.w,
                        aspectRatio: 0,
                        viewportFraction: 1.0,
                        onPageChanged: (index, reason) {
                          homeController.changeBannerIndex(index);
                        },
                      )
                    ),

                    Positioned(
                      bottom: 8.w,
                      child: SizedBox(
                        height: 5.w,
                        child: ListView.separated(
                          itemCount: homeController.indexPageBaseInfoModel?.carousels?.length ?? 0,
                          shrinkWrap: true,
                          scrollDirection: Axis.horizontal,
                          separatorBuilder: (context, index) {
                            return SizedBox(width: 4.w,);
                          },
                          itemBuilder: (BuildContext context, int index) {
                            return Container(
                              width: homeController.currentBannerIndex == index ? 12.w : 5.w,
                              height: 5.w,
                              decoration: BoxDecoration(
                                borderRadius: BorderRadius.circular(5.r),
                                color: Colors.white.withOpacity(homeController.currentBannerIndex == index ? 1.0 : 0.2),
                              ),
                            );
                          },
                        ),
                      )
                    )
                  ],
                ),

                SizedBox(height: 9.w,),

                ribbonWidget(homeController),
              ],
            ),
          );
        }
      ),
    );
  }

  // 功能区
  ribbonWidget(HomeController homeController) {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: 4.w),
      padding: EdgeInsets.only(left: 13.w, right: 13.w, bottom: 13.w),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(10.r)
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: homeController.indexPageBaseInfoModel!.features!.map((e) {
          return IconTextWidget(text: e.featuresName, icon: e.iconUrl, onTap: () {
            if (e.jumpType == CustomConstant.BANNER_TYPE_SHARE) {
              // 分享
              homeController.shareImg();
            } else if (e.jumpType == CustomConstant.BANNER_TYPE_APP) {
              homeController.toPage(e.redirectUrl, e.jumpType);
              // ShowSheetUtils.show(
              //   '为了给您提供准确有效的足球场以及俱乐部信息，请授权“畅点足球”APP使用您的定位信息',
              // );
              // StrUtils.jumpByUrl(e.redirectUrl, e.jumpType);
            }
          },);
        }).toList(),
      ),
    );
  }
}